<%@ page import="java.util.*,
                 com.actimind.actitime.beans.*,
                 com.actimind.actitime.user.*,
                 com.actimind.actitime.*,
                 com.actimind.actitime.resources.TaskListSortConstants"%>
<%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<bean:define id="form" name="TaskListForm" type="TaskListForm"/>

<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> Add Tasks to the List</title>
    <script language="JavaScript" src="../js/at.js"></script>
    <link rel="stylesheet" href="../css/at.css" type="text/css">

<script language="JavaScript">
function addSelectedTasks(f)
{
    var lst = "";
    for(i = 0; i < f.elements.length; i++)
    {
        var e = f.elements[i];
        if(e.name.indexOf("selected_") == 0 && e.checked)
        {
            if(lst.length > 0)
                lst += ",";
            lst += e.name.substring("selected_".length);
        }
    }
    window.opener.document.SubmitTTForm.addTaskList.value = lst;
    
    window.opener.document.SubmitTTForm.submit();
}
</script>
</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<at:form scope="session" action="/user/add_tasks" method="post">
<html:hidden property="submitted" value="true"/>

<table width="700" align="center" cellspacing="0" cellpadding="2" border="0">
<tr>
    <td><img src="../img/pixel.gif" width="1" height="8"></td>
</tr>
<tr>
    <td class="pagetitle">
        Add Tasks to the List
    </td>
</tr>
<tr>
    <td><at:errors/><html:img page="/img/pixel.gif" height="5"/></td>
</tr>
<tr>
    <td>
        <table cellspacing="0" cellpadding="10" align="center" border="0" width="100%">
        <tr>
            <td class="formbuttonpane">
                <table cellspacing="0" cellpadding="0" border="0" width="100%">
                    <td class="formbuttonpane" valign="middle">
                        <span class="text">Customer:</span>
                    </td>
                    <td class="formbuttonpane" valign="middle">
                        <at:select property="customerProject.shownCustomer" childSelect="customerProject.shownProject" firstChildText="-- All projects --" firstChildValue="0" style="width: 350px" width="350" maxlength="57">
                            <at:option value="0">-- All customers --</at:option>
                            <at:options collection="<%=Keys.CUSTOMERS_LIST_KEY%>" property="id" labelProperty="name"/>
                        </at:select>
                    </td>
                    <td class="formbuttonpane" valign="middle">
                        &nbsp;<span class="text">Project:</span>
                    </td>
                    <td class="formbuttonpane" valign="middle">
                        <at:select property="customerProject.shownProject" parentSelect="customerProject.shownCustomer" firstChildText="-- All projects --" firstChildValue="0" style="width: 250px" width="250" maxlength="38">
                            <option value=""> </option>
                            <option value=""> </option>
                            <option value=""> </option>
                            <option value=""> </option>
                            <at:options collection="<%=Keys.PROJECTS_LIST_KEY%>" property="id" parentProperty="customerId" labelProperty="name" />
                        </at:select>
                    </td>
                </table>
            </td>
        </tr>
        <tr>
            <td class="formbuttonpane">
                <input type="submit" value="   Show Tasks   " />
            </td>
        </tr>
        </table>
    </td>
</tr>
<tr>
    <td>

<logic:equal value="true" property="searchMade" name="form">
<logic:empty name="form" property="tasks">
<table width="100%">
<tr>
    <td class="text" align="center">
    There are no tasks to add.
    <td>
</tr>
</table>
</logic:empty>
</logic:equal>

<logic:notEmpty name="form" property="tasks">
<%!
    public static void printHeader(HttpServletResponse res, JspWriter out, String name, int sortBy, TaskListForm form)
        throws  java.io.IOException
    {
        String ascParam;
        if(form.getSortBy() == sortBy)
        {
            ascParam = form.isAsc() ? "false" : "true";
        }
        else
        {
            ascParam = "true";
        }

        String addTasksURL = res.encodeURL("add_tasks.do?submitted=true&sortBy=" + sortBy + "&asc=" + ascParam);
        out.print("<a class='listtblcolheader' href='" + addTasksURL + "'>" + name + "</a>");
        if(form.getSortBy() == sortBy)
        {
            out.print("&nbsp;<img src='../img/" + (form.isAsc() ? "tr_up.gif" : "tr_bot.gif") + "'>");
        }
    }
%>

<table width="100%" align="center" cellspacing="1" cellpadding="3" border="0">
<tr>
    <td width="20%" class="listtblcolheader" align="center">
        <% printHeader(response, out, "Customer", TaskListSortConstants.ORDER_TASKS_BY_CUSTOMER_PROJECT_TASK, form); %>
    </td>
    <td width="20%" class="listtblcolheader" align="center">
        <% printHeader(response, out, "Project", TaskListSortConstants.ORDER_TASKS_BY_PROJECT_CUSTOMER_TASK, form); %>
    </td>
    <td width="45%" class="listtblcolheader" align="center">
        <% printHeader(response, out, "Task", TaskListSortConstants.ORDER_TASKS_BY_TASK_CUSTOMER_PROJECT, form); %>
    </td>
    <td width="15%" align="center" width="100" class="listtblcolheader">
        Select Tasks<br/>to Add
    </td>
</tr>
<logic:iterate id="task" name="form" property="tasks" type="TaskBean">
<tr>
    <td class="listtblcell">
        <bean:write name="task" property="project.customer.name"/>
    </td>
    <td class="listtblcell">
        <bean:write name="task" property="project.name"/>
    </td>
    <td class="listtblcell">
        <bean:write name="task" property="name"/>
    </td>
    <logic:equal name="task" property="added" value="true">
    <td class="listtblcell" align="center">
        <span style="color: #666666">already added</span>
    </td>
    </logic:equal>
    <logic:equal name="task" property="added" value="false">
    <td class="listtblcell" align="center">
        <input type="checkbox" name="selected_<bean:write name="task" property="id"/>">
    </td>
    </logic:equal>
</tr>
</logic:iterate>
</table>

<br>

<table width="100%" align="center" cellspacing="0" cellpadding="5" border="0">
<tr>
    <td align="center" class="formbuttonpane">
        <input type="button" value="Add Selected Tasks to the List"
            onclick="addSelectedTasks(this.form); return false;"/>
    </td>
</tr>
</table>
</logic:notEmpty>

    </td>
</tr>
</table>


</at:form>

</body>
